<template>
	<view class="trim">
		<!-- 分段器 -->
		<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
			activeColor="#4cd964"></uni-segmented-control>
		<hr />

		<!-- 选择城市 -->
		<view class="content">
			<view class="plan" v-show="current === 0">
				<view class="plan-title">
					想去的城市
					<hr />
				</view>
				<view class="plan-city">
					<view class="plan-city-number">
						{{ selectedCities.length }}
					</view>
					<view class="plan-city-text">
						已选<br />城市
					</view>
					<!-- 已选城市列表 -->
					<view class="plan-city-button-container">
						<view class="plan-city-button" v-for="(city, index) in selectedCities" :key="index">
							<view class="text">
								{{ city }}
							</view>
							<view class="out">
								<uni-icons type="closeempty" size="30"></uni-icons>
							</view>
						</view>
					</view>
					<view class="plan-city-add-button" @click="goAddCity">
						<uni-icons type="plus" size="40" color="#22b589"></uni-icons>
					</view>
				</view>
				<view class="plan-title">
					服务 <text>(选服务时自动添加了当地城市)</text>
					<hr />
				</view>
				<!-- 选择服务 -->
				<view class="serve" v-for="(item,index) in tripList" :key="item">
					<!-- 精灵图 -->
					<view class="login-check">
						<view class="login_check_icon"></view>
					</view>
					<!-- 右侧信息 -->
					<view class="right">
						<view class="img">
							<img class="img-item" :src="item.imageUrl" alt="" />
						</view>
						<view class="right-content">
							<view class="right-content-top">
								{{item.name}}
							</view>
							<view class="right-content-bottom">
								价格: {{item.price}}人民币
							</view>
						</view>
						<view class="right-icon" :data-tripid="item.goodsId" @click="deleteService">
							<!-- 删除服务 -->
							<uni-icons type="trash" size="30"></uni-icons>
						</view>
					</view>
				</view>
				<!-- 开始定制按钮 -->
				<view class="footer">
					<view class="footer-center">
						<button size="mini"><uni-icons type="paperplane-filled" color="#fff" size="23"></uni-icons>
							用{{tripList.length}}项服务{{selectedCities.length}}个城市开始定制行程</button>
					</view>
				</view>
			</view>
			<view class="itinerary" v-show="current === 1">
				<uni-section>
					<uni-card title="尼泊尔7日游" sub-title="加德满都－博卡拉－帕坦" extra="未付款">
						<text class="uni-body">2016.1.25-2016.2.25 7天。</text>
					</uni-card>
				</uni-section>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		reqGetTripList,
		reqDeleteService
	} from '../../api/index.js'
	export default {
		data() {
			return {
				items: ['规划清单', '我的行程'],
				current: 0,
				selectedCities: ['北京', '上海', '广州', '深圳', '成都'],
				tripList: [],
			};
		},
		mounted() {
			this.getTripList();
		},
		methods: {
			// 切换页面
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			// 获取服务列表
			async getTripList() {
				const result = await reqGetTripList();
				if (result.code === 200) {
					this.tripList = result.data
				}
			},
			// 删除服务
			async deleteService(event) {
				const tripid = event.currentTarget.dataset.tripid;
				await reqDeleteService(tripid);
				this.getTripList();
				uni.showToast({
					title: '删除成功',
					icon: 'success'
				})
			},
			// 去 添加城市
			goAddCity(){
				uni.navigateTo({
					url:'/pages/trim/addCity/index'
				})
			}
		},
		// computed: {
		// 	//获取各个Id
		// 	extractedGoodsIds() {
		// 		return this.tripList.map(item => item.goodsId);
		// 	},
		// 	// 将各个Id分段
		// 	segmentedGoodsIds() {
		// 		const chunkSize = 5; // 每个块的大小
		// 		const segmentedArray = [];

		// 		for (let i = 0; i < this.tripList.length; i += chunkSize) {
		// 			segmentedArray.push(this.tripList.slice(i, i + chunkSize).map(item => item.goodsId));
		// 		}

		// 		return segmentedArray;
		// 	}
		// }
	};
</script>


<style scoped lang="scss">
	.trim {
		.plan-title {
			padding-left: 50rpx;
			padding-top: 20rpx;
			margin-bottom: 20rpx;
		}

		.content {
			margin-bottom: 30rpx;
			padding: 0 20rpx;

			.plan {
				.plan-city {
					display: flex;

					.plan-city-number {
						font-size: 50rpx;
						height: 90rpx;
						line-height: 90rpx;
						margin: 0 10rpx;
					}

					.plan-city-text {
						min-width: 70rpx;
						padding-right: 6rpx;
						height: 90rpx;
						border-right: 2rpx solid rgb(93, 74, 74);
					}

					.plan-city-button-container {
						display: flex;
						overflow-x: auto;

						.plan-city-button {
							min-width: 150rpx;
							max-height: 40rpx;
							border-radius: 10rpx;
							margin: 10rpx;
							background-color: rgb(61, 191, 98);
							color: white;
							padding: 20rpx;
							display: flex;
							justify-content: space-between;
							align-items: center;
						}
					}

					.plan-city-add-button {
						margin-top: 10rpx;
					}
				}

			}

			.serve {
				// background-color: #ccc;
				display: flex;
				margin-bottom: 20rpx;

				.login-check {
					width: 7%;
					position: relative;
					padding-right: 4rpx;

					.login_check_icon {
						width: 24px;
						height: 24px;
						position: absolute;
						left: 0;
						top: 0;
						right: 0;
						bottom: 0;
						margin: auto;
						background-repeat: no-repeat;
						background-size: 24px 48px;
						background-color: #22b589;
						border-radius: 50%;
						background-image: url('https://8.idqqimg.com/edu/mobilev2/m-core/1f3256dafe9eb438879b434bd4105394.png');
						background-position: 0 0;
						background-position: 0 -24px;
					}
				}


				.right {
					background-color: #eee;
					display: flex;
					width: 100%;
					border: 2rpx solid #ccc;

					.img {
						margin: 20rpx;
						width: 25%;

						.img-item {
							width: 100%;
							height: 100%;
						}
					}

					.right-content {
						width: 60%;
						margin: 24rpx 10rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.right-content-top {
							font-weight: 700;
						}

						.right-content-bottom {
							font-size: 26rpx;
						}
					}

					.right-icon {
						width: 10%;
						line-height: 190rpx;
					}
				}

			}
		}

		.footer {
			margin-top: 140rpx;
			display: flex;
			justify-content: center;

			.footer-center {
				button {
					background-color: #22b589;
					font-size: 30rpx;
				}
			}

		}
	}
</style>